package com.xht.controller;

import com.xht.domain.ResponseResult;
import com.xht.domain.dto.AddArticleDto;
import com.xht.domain.dto.ArticleChangeStatusDto;
import com.xht.service.ArticleService;
import com.xht.vo.AdminUpdateArticleVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/content/article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    /**
     * 添加 文章
     *
     * @param article
     * @return
     */
    @PostMapping
    public ResponseResult add(@RequestBody AddArticleDto article) {
        return articleService.add(article);
    }

    /**
     * 查询文章列表
     */
    @GetMapping("/list")
    public ResponseResult list(Integer pageNum, Integer pageSize, String title, String summary, Long categoryId) {
        return articleService.AdminList(pageNum, pageSize, title, summary, categoryId);
    }

    /**
     * 修改文章--中的回显 文章详情
     */
    @GetMapping("/{id}")
    public ResponseResult fix_ReshowArticle(@PathVariable Integer id) {
        return articleService.fix_ReshowArticle(id);
    }

    /**
     * 修改文章--更新文章
     */
    @PutMapping
    public ResponseResult fix_UpdateArticle(@RequestBody AdminUpdateArticleVo adminUpdateArticleVo) {
        return articleService.fix_UpdateArticle(adminUpdateArticleVo);
    }

    /**
     * 逻辑删除 文章
     */
    @DeleteMapping("/{id}")
    public ResponseResult deleteArticle(@PathVariable Integer id) {
        return articleService.deleteArticle(id);
    }

    /**
     * 修改文章状态
     */
    @PutMapping("/changeStatus")
    public ResponseResult changeStatus(@RequestBody ArticleChangeStatusDto articleChangeStatusDto) {
        return articleService.changeStatus(articleChangeStatusDto);
    }

}
